package com.zhiyume.service;

import com.zhiyume.dao.api.TCommentMapper;
import com.zhiyume.dao.entity.TComment;
import com.zhiyume.dao.entity.TCommentCriteria;
import com.zhiyume.service.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by wang on 17/11/5.
 */
@Service
public class CommentService {
    private static final String MODULE = CommentService.class.getName();
    private static final Logger logger = LoggerFactory.getLogger(CommentService.class);

    @Autowired
    private TCommentMapper commentMapper;

    public List<TComment> findCommentByInformationId(Long id){
        TCommentCriteria t = new TCommentCriteria();
        TCommentCriteria.Criteria c = t.createCriteria();
        c.andInformationIdEqualTo(id);
        return commentMapper.selectByExample(t);
    }

    public List<TComment> findComment(TComment comment){
        TCommentCriteria t = new TCommentCriteria();
        TCommentCriteria.Criteria c = t.createCriteria();
        if(comment.getId()!=null){
            c.andIdEqualTo(comment.getId());
        }
        if(comment.getInformationId()!=null){
            c.andInformationIdEqualTo(comment.getInformationId());
        }
        if(comment.getUserId()!=null){
            c.andUserIdEqualTo(comment.getUserId());
        }
        if(StringUtil.isNotBlank(comment.getUserName())){
            c.andUserNameLike("%"+comment.getUserName()+"%");
        }
        return commentMapper.selectByExample(t);
    }
}
